import sys
import json
import pandas as pd

sys.path.append(r"C:\Zhunda_HTML\restaurant")  # 添加包路径

from Entity.Guest import Guest
from Entity.Waiter import Waiter
from Entity.Manu import Manu
from Entity.Cook import Cook
from BLL.CookBll import CookBll
from BLL.GuestBll import GuestBll
from BLL.WaiterBll import WaiterBll

if __name__ == "__main__":
    # 实例化类对象
    waiter = Waiter("小李", False, "78978999")
    guest = Guest("小王", False, "7897890099")
    cook = Cook("老张", True, "78978999")
    # 菜单
    huiguorou = Manu("回锅肉", 24.0, "麻辣")
    yuxiangqiezi = Manu("鱼香茄子", 25.0, "麻辣")
    yuxiangrousi = Manu("鱼香肉丝", 28.0, "麻辣")
    guobaroupian = Manu("锅巴肉片", 24.0, "麻辣")

    manu_list = [huiguorou, yuxiangqiezi, yuxiangrousi, guobaroupian]
    txt_list = []

    print("{0}\t{1}\t{2}\t{3}".format("序号", "菜名", "单价", "口味"))
    for i, m in enumerate(manu_list):
        if m.status == 0:
            print("{0}\t{1}\t{2}\t{3}".format(i + 1, m.name, m.price, m.note))
            txt_list.append(
                {
                    "序号": (i + 1),
                    "菜名": m.name,
                    "单价": m.price,
                    "口味": m.note
                }
            )
    print("=========================================================")
    print("本地化保存菜单完成！！！")
    json_data = json.loads(str(txt_list).replace("\'", "\""))
    with open('menu.json', "a+", encoding="UTF-8") as file:
        json.dump(json_data, file, ensure_ascii=False, indent=2)
    pd.DataFrame(txt_list).to_csv("menu.csv")
    pd.DataFrame(txt_list).to_excel("menu.xlsx")
    print("=========================================================")

    # 客户点餐
    manu_item = input("请输入菜品编号:")
    manu = manu_list[int(manu_item) - 1]
    manu.status = 1
    # 实例化业务对象
    cookBll = CookBll()
    waiterBll = WaiterBll()
    guestBll = GuestBll()
    # 通知厨师做菜
    print("=========================================================")
    cookBll.cook(waiter, manu)
    # 送菜完毕   
    print("=========================================================")
    waiterBll.serve(guest, manu)
    # 用餐结束  
    print("=========================================================")
    guestBll.eat(guest, manu)
    # 客户付款
    print("=========================================================")
    waiterBll.pay(guest, manu)
